<template>
  <div>
    <el-row>
      <tableComponents
        :pagination="{currentPage,pageSize,total:list.all_num}"
        @handleCurrentChange="handleCurrentChange"
        @handleSizeChange="handleSizeChange"
        @sendUserSearch="getSearch"
        :searchData="userSearchData"
        :isHaveExport="false"
        :isHaveAdd="false"
      >
        <template v-slot:table>
          <el-table
            ref="multipleTable"
            :data="list.data"
            v-loading="loading"
            stripe
            header-row-class-name="head_color"
            tooltip-effect="dark"
            style="width: 99.9%"
            @selection-change="handleSelectionChange"
          >
            <el-table-column type="selection" class="tc" width="35"></el-table-column>

            <el-table-column label="头像" min-width="80" align="center">
              <template slot-scope="scope">
                <div class="img_bor_tx" style="margin:0 auto">
                  <img :src="$fnc.getImgUrl(scope.row.avatar)" alt />
                </div>
              </template>
            </el-table-column>

            <el-table-column label="用户信息" min-width="200">
              <template slot-scope="scope">
                <div class="tab_div">
                  <div>
                    <span>用户昵称：</span>
                    <span>{{scope.row.nickname || '----'}}</span>
                  </div>
                  <div>
                    <span>会员账号：</span>
                    <span>{{scope.row.username}}</span>
                  </div>
                  <div>
                    <span>用户等级：</span>
                    <span class="rat" v-show="scope.row.rating_cn">{{scope.row.rating_cn}}</span>
                  </div>
                </div>
              </template>
            </el-table-column>

            <el-table-column label="留言内容" min-width="257">
              <template slot-scope="scope">
                <div class="tab_div">
                  <div>
                    <span>真实姓名：</span>
                    <span>{{scope.row.name}}</span>
                  </div>
                  <div>
                    <span>留言内容：</span>
                    <span>{{scope.row.content}}</span>
                  </div>
                  <div>
                    <span>时间：</span>
                    <span>{{scope.row.created_time | getTimeFormat}}</span>
                  </div>
                </div>
              </template>
            </el-table-column>

            <el-table-column label="回复内容" min-width="258">
              <template slot-scope="scope">
                <div class="tab_div">
                  <div>
                    <span>回复内容：</span>
                    <span>{{scope.row.remark}}</span>
                  </div>
                  <div>
                    <span>时间：</span>
                    <span>{{scope.row.update_time | getTimeFormat}}</span>
                  </div>
                </div>
              </template>
            </el-table-column>

            <el-table-column label="操作" align="center" min-width="150">
              <template slot-scope="scope">
                <el-button
                  :loading="$store.state.isLoading"
                  type="primary"
                  size="mini"
                  @click="showEditDialog(scope.row.id)"
                >编辑</el-button>
                <el-button
                  :loading="$store.state.isLoading"
                  size="mini"
                  @click="deleteNew(scope.$index, scope.row.id)"
                  type="danger"
                >删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </template>
        <template v-slot:footerLeft>
          <a class="aBtn aBtn_1 aBtn_lan2" @click="delSelection">删除</a>
        </template>
      </tableComponents>

      <MsgEdit @parent="reload" :show.sync="show" :editId="editId" :clickNum="clickNum"></MsgEdit>
    </el-row>
  </div>
</template>
<script>
import switchc from "../currency/Swich";
import MsgEdit from "@/components/user/msg_edit.vue";

import HeadTitle from "@/components/currency/HeadTitle.vue";
import msgSearch from "@/components/currency/msgSearch.vue";
import { userMsgSearchData } from "@/assets/js/searchData/searchData"; //引入搜索的数据
export default {
  data() {
    return {
      userSearchData: userMsgSearchData,
      show: false,
      loading: false,
      list: [],
      allPage: 0,
      allNum: 0,
      pageSize: 10,
      currentPage: 1,
      editId: "",
      multipleSelection: "",
      arr: [],
      visible: false,
      clickNum: 0,
      updataIndex: "",
      searchAll: {}
    };
  },
  components: {
    switchc,
    MsgEdit,
    HeadTitle,
    msgSearch
  },
  methods: {
    getSearch(obj) {
      this.searchAll = obj;
      this.$router.push(this.$route.path + "?page=" + 1);
      this.getNewsAll(obj);
    },
    getNewsAll(data) {
      this.loading = true;
      var params = {};
      data = data || {};
      params = data;
      this.$api.getUser.getMsgList(params).then(res => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        this.loading = false;
      });
    },
    handleSizeChange(val) {
      var params = this.searchAll;
      params.page = "";
      params.page_size = val;
      this.getNewsAll(params);
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      this.$router.push(this.$route.path + "?page=" + val);
    },
    handleSwitch(val, id) {
      //审核
      var params = {};
      params["id"] = id;
      val == true ? (params["is_check"] = 1) : (params["is_check"] = 0);
      this.$api.getUser.msgCheck(params).then(res => {
        // this.getNewsAll();
      });
    },
    handleSelectionChange(val) {
      //多选框赋值
      this.multipleSelection = val;
    },
    delSelection() {
      //删除
      var str = "";
      for (var i in this.multipleSelection) {
        console.log(this.multipleSelection[i]["id"]);
        str += this.multipleSelection[i].id + "@";
      }
      str = str.slice(0, -1);
      var data = { id_str: str };
      this.$api.getUser.MsgDel(data).then(res => {
        if (res.data.code == 200) {
          this.getNewsAll(this.searchAll);
        }
      });
    },
    deleteNew(index, id) {
      console.log(index);
      this.$swal({
        title: "您确定要删除这条信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思"
      }).then(willDelete => {
        if (willDelete.value) {
          var data = { id_str: id };
          this.$api.getUser.MsgDel(data).then(res => {
            if (res.data.code == 200) {
              this.$swal("删除成功！", "您已经删除了这条信息。", "success");
              console.log(this.list);
              this.getNewsAll(this.searchAll);
            } else {
              this.$swal("删除失败！", "出错啦！", "success");
            }
          });
        }
      });
    },
    showEditDialog(id) {
      this.show = true;
      this.editId = id;
      this.clickNum++;
      console.log(this.clickNum);
    },
    reload(id) {
      this.getNewsAll(this.searchAll);
    }
  },
  beforeCreate() {
    this.loading = true; //数据未加载之前调用loading
  },
  created() {
    this.getNewsAll();
    this.loading = false;
  },
  computed: {},
  watch: {
    atch: {
      $route() {
        var params = this.searchAll;
        params.page = this.$route.query.page || 1;
        params.page_size = this.pageSize;
        this.getNewsAll(params);
        this.currentPage = Number(this.$route.query.page) || 1;
      }
    }
  }
};
</script>

<style lang="less" scoped>
thead > tr > th {
  height: 45px;
  line-height: 45px;
}
td,
th {
  border: 1px solid #e1e3e4;
  font-size: 12px;
}
th {
  background: #f8f8f8;
  font-weight: normal;
  color: #323437;
}
td {
  height: 75px;
  color: #000;
}
.caozuo {
  padding-left: 50px;
}
.pl {
  padding-left: 15px;
}
.chkBox {
  display: block;
  margin: 0 auto;
  width: 18px;
  height: 18px;
  background: #fff;
}
.aBtn_1 {
  padding: 10px;
}
</style>
